/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.SQLServerDB;

/**
 *
 * @author Canh
 */
public class Configs {

    final String CONFIGS_GETVALUE = "SELECT VALUE FROM CONFIGS WHERE NAME LIKE ?";
    final String CONFIGS_SETVALUE = "{call Configs_SetValue(?, ?)}";

    public String getValue(String name) {
        try {
            SQLServerDB db = new SQLServerDB();
            PreparedStatement pr = db.getConn().prepareStatement(CONFIGS_GETVALUE);
            pr.setString(1, name);
            ResultSet rs = pr.executeQuery();
            if (rs.next()) {
                return rs.getString(0);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Configs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public boolean setValue(String name, String value) {
        try {
            SQLServerDB db = new SQLServerDB();
            CallableStatement pr = db.getConn().prepareCall(CONFIGS_SETVALUE);
            pr.setString(1, name);
            pr.setString(2, value);
            ResultSet rs = pr.executeQuery();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Configs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }
}
